<!--
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/3/25-11:23
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------
*-->

{extend name='public/base' /}
{block name="css"}
<link href="__PLUGS__/dropdown/dropdown.css?v=1.0" rel="stylesheet">
{/block}
{block name="content"}

<div class="layui-col-md12">

    <div class="layui-card">
        <div class="layui-card-body layui-row ">

            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">

                    <div class="layui-inline">
                        <label class="layui-form-label">部门名称：</label>
                        <div class="layui-input-inline">
                            <input name="dname" class="layui-input" value="" type="text" placeholder="请输入部门名称">
                        </div>
                    </div>

                    <div class="layui-inline" style="padding-left: 20px;">
                        <button class="layui-btn icon-btn layui-btn-sm" lay-filter="search" lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" onclick="javascript:window.location.reload();">
                            <i class="layui-icon layui-icon-refresh"></i> 重置
                        </button>
                    </div>

                </div>

            </form>

        </div>

    </div>


    <div class="layui-card">
        <div class="layui-card-body layui-row ">
            <div class="layui-card-header" style="line-height: 55px;">
                <div class="layui-btn-container do_btn">
                    <!--按钮区-->
                    <button class="layui-btn layui-btn-sm" data-type="add"><i class="layui-icon"></i>新增部门</button>
                    <button class="layui-btn layui-btn-sm layui-btn-primary" data-type="reload"><i class="fa fa-refresh"></i> 刷新</button>

                </div>
            </div>

        </div>

    </div>

    <div class="layui-card">

        <div class="layui-card-body">

            <!--表格区-->

            <div class="yys-fluid yys-wrapper">
                <div class="layui-row lay-col-space20">
                    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                        <section class="yys-body">
                            <div class="yys-body-content clearfix changepwd">
                                <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                    <div class="user-tables">
                                        <table id="tableFilter" lay-filter="tableFilter"> </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>


{/block}


{block name="js"} <!--js处理区-->


<!--模板-->
<script type="text/html" id="operationTpl">

    <button class="layui-btn layui-btn-xs" lay-filter="ft" lay-dropdown="{align:'center', menus: [{layIcon:'layui-icon-add-circle-fine',txt: '新增子部门', event:'add'},{layIcon:'layui-icon-edit',txt: '编辑部门', event:'edit'}, {layIcon: 'layui-icon-delete',txt: '删除部门', event:'del'}]}">
        <span>更多操作</span>
        <i class="layui-icon layui-icon-triangle-d"></i>
    </button>
</script>



<script type="text/html" id="status">
    <input type="checkbox" name="status"  lay-data="{{d.status}}" value="{{d.id}}"  lay-filter="status" lay-skin="switch"  lay-text="启用|不启用"  {{ d.status == 1 ? 'checked' : '' }}>
</script>


<script>

    layui.config({
        base: "__PLUGS__/dropdown/"
    }).use(['element', 'table', 'form', 'jquery', 'lucky','dropdown'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var dropdown=layui.dropdown;
        form.render();
        table.render({
            elem: '#tableFilter',
            url:"{:url('index')}",
            toolbar: true,
            defaultToolbar: ['filter', 'exports', 'print'],
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:50
                ,limits:[50,60,70,80]
            },
            //height: 'full-100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {field: 'id',  title: 'ID',width:60},
                {field: 'title_show', minWidth: 100, title: '部门名称', align: 'left',},
                {field:'status',title:'是否启用',templet: '#status',width:110 ,unresize: true},
                {field: 'charger',style:'cursor: pointer;',title: '负责人',width:120},
                {field: 'pnum',style:'cursor: pointer;',title: '编制人数',width:110,sort:true},
                {field: 'snum',style:'cursor: pointer;',title: '目前人数',width:110,sort:true},
                {field: 'beizhu',style:'cursor: pointer;',title: '备注',width:160},
                {field: 'create_time', title: '添加时间',align: 'center',width:180},
                {fixed: 'right',templet: '#operationTpl', width: 130, align: 'center', title: '操作'}
            ]],
            done: function (res) {
                dropdown.suite();
            }
        });


        /**
         * 监听是否显示操作
         */
        form.on('switch(status)', function(obj){
            var _id=parseInt(obj.value);
            var pan=obj.elem.checked;
            var status;
            if (pan===false){
                status=0;
            }else {
                status=1;
            }
            lucky.Change_status("{:url('common/changeStatus')}","table_id","co_department",_id,"status",status, obj.othis);
        });




        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent==="add"){
                var url="{:url('addDepartment')}?id="+_id;
                lucky.CreateForm("添加子部门",'57%','70%',url,"table_id",1);

            }else if(layEvent==="edit"){

                var url="{:url('editDepartment')}?id="+_id;
                lucky.CreateForm("编辑部门",'57%','70%',url,"table_id",1);

            }else if(layEvent==="del"){
                lucky.Delete_data(_id,"{:url('del')}","table_id");
            }
        });

        var active = {
            add:function(){
                lucky.CreateForm("添加部门",'57%','70%',"{:url('addDepartment')}","table_id",1);
            },
            del: function(){ //获取选中数据
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.Delete_data(id,"{:url('del')}","table_id");
            },
            reload: function(){
                lucky.CreateReload("table_id");
            }
        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >


{/block}
